//
//  MineViewController.m
//  NoNameAmazing
//
//  Created by liuyang on 2017/6/22.
//  Copyright © 2017年 北京执行力科技有限公司. All rights reserved.
//

#import "MineViewController.h"
#import "MineInfoController.h"
#import "MineSetPassController.h"
#import "MineMessageController.h"
#import "BasicInfoController.h"
#import "MineWorkController.h"
#import "MinetInfoModel.h"
#import "SbModel.h"

@interface MineViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *headImage;
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UILabel *classLab;
@property (weak, nonatomic) IBOutlet UIView *lineView1;
@property (weak, nonatomic) IBOutlet UIView *lineView2;
@property(nonatomic,strong) MinetInfoModel * minetInfoModel;
@property (weak, nonatomic) IBOutlet UIImageView *infoImage;
@property (weak, nonatomic) IBOutlet UILabel *firstName;
@property (weak, nonatomic) IBOutlet UIImageView *secImege;
@property (weak, nonatomic) IBOutlet UILabel *secName;
@property (weak, nonatomic) IBOutlet UIImageView *thrImage;
@property (weak, nonatomic) IBOutlet UILabel *thrName;
@property (weak, nonatomic) IBOutlet UIImageView *fourImage;
@property (weak, nonatomic) IBOutlet UILabel *fourName;
@property(nonatomic,strong) SbModel * sbModel;
@property(nonatomic,strong) NSArray * sbArray;


@end

@implementation MineViewController
{
    NSURL *_URL;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    //7获取用户信息
    _sbArray = [NSArray array];
    [self requestInfo];
    [self loadData];
     [self requestHeadImage];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(head:) name:@"head" object:nil];
}

-(void)createUI
{
    
    self.view.backgroundColor = UIColorFromRGB(0xEFEFF5);
    self.lineView1.backgroundColor = UIColorFromRGB(0xE3E3E9);
    self.lineView2.backgroundColor = UIColorFromRGB(0xE3E3E9);
}
- (IBAction)headImageBtnClick:(id)sender {
    MineInfoController *mineInfoController = [[MineInfoController alloc] init];
    mineInfoController.minetInfoModel = _minetInfoModel;
    [self.navigationController pushViewController:mineInfoController animated:YES];
}
- (IBAction)setBtnClick:(id)sender {
    _sbModel = self.sbArray[3];
    if (_sbModel.MENUID==32) {
        BasicInfoController *basicInfoController = [[BasicInfoController alloc] init];
        [self.navigationController pushViewController:basicInfoController animated:YES];
    }else if (_sbModel.MENUID==33){
        MineWorkController *mineWorkController = [[MineWorkController alloc] init];
         mineWorkController.url = _sbModel.MENURESOURCEURL;
        [self.navigationController pushViewController:mineWorkController animated:YES];
    }else if (_sbModel.MENUID==34){
        MineMessageController *mineMessageController = [[MineMessageController alloc] init];
        [self.navigationController pushViewController:mineMessageController animated:YES];
    }else if (_sbModel.MENUID==35){
        MineSetPassController *mineSetPassController = [[MineSetPassController alloc] init];
        [self.navigationController pushViewController:mineSetPassController animated:YES];
    }
}
- (IBAction)setPassBtnClick:(id)sender {
    _sbModel = self.sbArray[2];
    if (_sbModel.MENUID==32) {
        BasicInfoController *basicInfoController = [[BasicInfoController alloc] init];
        [self.navigationController pushViewController:basicInfoController animated:YES];
    }else if (_sbModel.MENUID==33){
        MineWorkController *mineWorkController = [[MineWorkController alloc] init];
         mineWorkController.url = _sbModel.MENURESOURCEURL;
        [self.navigationController pushViewController:mineWorkController animated:YES];
    }else if (_sbModel.MENUID==34){
        MineMessageController *mineMessageController = [[MineMessageController alloc] init];
        [self.navigationController pushViewController:mineMessageController animated:YES];
    }else if (_sbModel.MENUID==35){
        MineSetPassController *mineSetPassController = [[MineSetPassController alloc] init];
        [self.navigationController pushViewController:mineSetPassController animated:YES];
    }
}
- (IBAction)basicInfoBtnClick:(id)sender {
    _sbModel = self.sbArray[0];
    if (_sbModel.MENUID==32) {
        BasicInfoController *basicInfoController = [[BasicInfoController alloc] init];
        [self.navigationController pushViewController:basicInfoController animated:YES];
    }else if (_sbModel.MENUID==33){
        MineWorkController *mineWorkController = [[MineWorkController alloc] init];
         mineWorkController.url = _sbModel.MENURESOURCEURL;
        [self.navigationController pushViewController:mineWorkController animated:YES];
    }else if (_sbModel.MENUID==34){
        MineMessageController *mineMessageController = [[MineMessageController alloc] init];
        [self.navigationController pushViewController:mineMessageController animated:YES];
    }else if (_sbModel.MENUID==35){
        MineSetPassController *mineSetPassController = [[MineSetPassController alloc] init];
        [self.navigationController pushViewController:mineSetPassController animated:YES];
    }

    
   
    
}
- (IBAction)workBtnClick:(id)sender {
    _sbModel = self.sbArray[1];
    if (_sbModel.MENUID==32) {
        BasicInfoController *basicInfoController = [[BasicInfoController alloc] init];
        [self.navigationController pushViewController:basicInfoController animated:YES];
    }else if (_sbModel.MENUID==33){
        MineWorkController *mineWorkController = [[MineWorkController alloc] init];
        mineWorkController.url = _sbModel.MENURESOURCEURL;
        [self.navigationController pushViewController:mineWorkController animated:YES];
    }else if (_sbModel.MENUID==34){
        MineMessageController *mineMessageController = [[MineMessageController alloc] init];
        [self.navigationController pushViewController:mineMessageController animated:YES];
    }else if (_sbModel.MENUID==35){
        MineSetPassController *mineSetPassController = [[MineSetPassController alloc] init];
        [self.navigationController pushViewController:mineSetPassController animated:YES];
    }}

- (void)loadData{
    
    NSDictionary *params = @{@"roleid":[us objectForKey:kRoleid],@"pid":[us objectForKey:kStudentsMenuId4]};
    [NetWorkManager requestWithType:1 withUrlString:@"/appmenu/appgetMenubyPid.do" withParaments:params withSuccessBlock:^(id object) {
        NSString *BaseURL = [us objectForKey:baseUrl];
        if ([object[@"status"] integerValue] == 1) {
            self.sbArray = [SbModel mj_objectArrayWithKeyValuesArray:object[@"menuList"]];
        }
        _sbModel = self.sbArray[0];
        [self.infoImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseURL,_sbModel.MENUIMG]]];
        self.firstName.text = _sbModel.MENUNAME;
        _sbModel = self.sbArray[1];
        [self.secImege sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseURL,_sbModel.MENUIMG]]];
        self.secName.text = _sbModel.MENUNAME;

        _sbModel = self.sbArray[2];
        [self.thrImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseURL,_sbModel.MENUIMG]]];
        self.thrName.text = _sbModel.MENUNAME;

        _sbModel = self.sbArray[3];
        [self.fourImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseURL,_sbModel.MENUIMG]]];
        self.fourName.text = _sbModel.MENUNAME;

    } withFailureBlock:^(NSError *error) {
        
    } progress:^(float progress) {
        
    }];
}



-(void)requestInfo
{
    NSDictionary *params = @{@"userid":[us objectForKey:kUserid]};
    [NetWorkManager requestWithType:1 withUrlString:@"/selectInformation/getAccountInformation.do" withParaments:params withSuccessBlock:^(id object) {
       if ([object[@"message"]isEqualToString:@"成功"]) {
           _minetInfoModel = [MinetInfoModel mj_objectWithKeyValues:object[@"informationList"]];
           self.nameLab.text = _minetInfoModel.xm;
           self.classLab.text = _minetInfoModel.yx;
       }
        
    } withFailureBlock:^(NSError *error) {
        
        
    } progress:^(float progress) {
        
    }];
}

-(void)requestHeadImage
{
    NSDictionary *params = @{@"userid":[us objectForKey:kUserid]};
    [NetWorkManager requestWithType:1 withUrlString:@"/informationsite/getTitleImage.do" withParaments:params withSuccessBlock:^(id object) {
        if ([object[@"message"]isEqualToString:@"成功"]) {
            NSString * BaseURL = [us objectForKey:baseUrl];
            NSString * headImage = [NSString stringWithFormat:@"%@%@",BaseURL,object[@"imgUrl"]];
            _URL = [NSURL URLWithString:headImage];
            [self.headImage sd_setImageWithURL:_URL];
        }
        
    } withFailureBlock:^(NSError *error) {
        
        
    } progress:^(float progress) {
        
    }];
}
-(void)head:(NSNotification *)sender{
    //打印通知传过来的数值
    _URL = [NSURL URLWithString:sender.userInfo[@"image"]];
    [self.headImage sd_setImageWithURL:_URL];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
